#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#define printf
using ll = int64_t;
#define sl static inline
ll n,q;
std::map<ll, ll> m;
#define P(v)do{printf("[DEBUG] %s=%lld\n",#v,(v));}while(false)

sl void solve(){
    std::cin>>n>>q;
    m.clear();
    bool isnotok=false;
    ll last=-1;
    for(ll i=1;i<=n;i++){
        ll a,b;
        std::cin>>a>>b;
        if(isnotok)continue;
        if(a!=last+1){
            isnotok=true;
            continue;
        }
        m[a]+=b;
        last=a;
    }
    while(q--){
        ll nq,ans=0;
        std::cin>>nq;
        auto nm = m;
        if(nm.empty()){
            std::cout<<"-1\n";
            continue;
        }
        while(nm.size()&&nq){
            P(nq);
            auto pm = nm.lower_bound(nq);
            if(pm==nm.begin()){
                ans=-1;
                break;
            }
            if(pm!=nm.end()&&pm->first>nq){
                if(pm!=nm.begin()){
                    pm--;
                }else{
                    ans=-1;
                    break;
                }
            }
            ll getnum = nq/(std::prev(pm)->first+1);
            P(std::prev(pm)->first+1);
            if(getnum==0){
                ans=-1;
                break;
            }
            for(auto i=nm.begin();i!=pm;i++){
                getnum=std::min(getnum,i->second);
            }
            P(getnum);
            nq-=getnum*(std::prev(pm)->first+1);
            bool iserase=false;
            ll erasekey=0;
            for(auto i=nm.begin();i!=pm;){
                if(iserase){
                    i=nm.erase(i);
                    continue;
                }
                i->second-=getnum;
                if(i->second==0){
                    erasekey=i->first;
                    iserase=true;
                    i=nm.erase(i);
                }else{
                    i++;
                }
            }
            if (erasekey) {
                auto p=nm.lower_bound(erasekey);
                for(;p!=nm.end();){
                    p=nm.erase(p);
                }
            }
            ans+=getnum;
        }
        P(nq);
        P(nm.size());
        if(nq!=0){
            std::cout<<"-1\n";
            continue;
        }
        std::cout<<(ans==0?-1:ans)<<"\n";
    }
}

int main(){
    // std::iostream::sync_with_stdio(false);
    // std::cin.tie(nullptr);


    ll t;
    std::cin>>t;
    while(t--){
        solve();
    }
}